package com.jjvu.news.service.impl;

import com.github.pagehelper.PageHelper;
import com.jjvu.news.dao.Sys_user;
import com.jjvu.news.domain.LeftDao;
import com.jjvu.news.service.LeftService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.List;

@Service("leftService")
public class LeftServiceImpl implements LeftService {
    @Autowired
    private LeftDao leftDao;
    public List<Sys_user> findAllUser() {
        List<Sys_user> listUser=leftDao.findAllUser();
        for (Sys_user user:listUser) {
            if (user.getState()=="1"){
                user.setState("启用状态");
            }
            if (user.getState()=="0"){
                user.setState("禁用状态");
            }
            user.setPassword("***");
        }

        return listUser;
    }

    public List<Sys_user> findUserPageall(Integer page, Integer size) {
        PageHelper.startPage(page, size);
        List<Sys_user> users=leftDao.findAllUser();
        for (Sys_user user1 : users) {
            if(user1.getState()=="1") {
                user1.setState("启用状态");
            }
            if(user1.getState()=="0") {
                user1.setState("禁用状态");
            }
            user1.setPassword("***");
        }
        return users;
    }

    public Sys_user findUserById(Integer uid) {
        return leftDao.findUserById(uid);
    }

    public boolean updateUser(Sys_user user) {

        return leftDao.updateUser(user);
    }

    public boolean addUser(Sys_user user) {
        return leftDao.addUser(user);
    }

    public boolean deleteUser(Integer uid) {
        return leftDao.deleteUser(uid);
    }

    public boolean findUserBy(Sys_user user) {
        Sys_user u = leftDao.findUserBy(user);
        if (u!=null){
            return true;
        }
        return false;
    }


}
